﻿using System;

namespace Lesson9_练习题
{
    class Program
    {
        #region 练习一
        //使用params函数，求多个数字的和以及平均数、
        static void Calc1(params float[] nums)
        {
            if(nums.Length == 0)
            {
                Console.WriteLine("未传参");
                return;
            }

            float sum = 0;
            float avg = 0;
            for (int i = 0; i < nums.Length; i++)
            {
                sum += nums[i];
            }
            avg = sum / nums.Length;
            Console.WriteLine("和为{0}，平均值为{1}", sum, avg);
        }
        #endregion

        #region 练习二
        //使用params函数，求多个数字的偶数和奇数和
        static void Calc2(params float[] nums)
        {
            if (nums.Length == 0)
            {
                Console.WriteLine("未传参");
                return;
            }

            float sum1 = 0;
            float sum2 = 0;
            for(int i = 0; i < nums.Length;i++)
            {
                if(nums[i] % 2 == 0)
                {
                    sum1 += nums[i];
                }
                else
                {
                    sum2 += nums[i];
                }
            }
            Console.WriteLine("偶数和为{0}，奇数和为{1}", sum1, sum2);
        }
        #endregion


        static void Main(string[] args)
        {
            #region 练习一
            Calc1();
            Calc1(1.3f, 24, 12.3f, 22);
            #endregion

            #region 练习二
            Calc2();
            Calc2(12, 23, 34);
            #endregion
        }
    }
}